package com.weilive.api.gate.json.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.weilive.api.ServerErrors;
import com.weilive.api.gate.json.protocol.CSA_ReportUser;
import com.weilive.api.gate.json.protocol.CSQ_ReportUser;
import com.weilive.api.service.UserSystem;
import com.weilive.core.protocol.json.JsonRequest;
import com.weilive.core.protocol.json.JsonRequestHandler;
import com.weilive.core.protocol.json.JsonResponse;

@Service
public class CSQ_ReportUser_JsonHandler extends JsonRequestHandler {

	@Autowired
	private UserSystem userSystem;

	public Class<?> getRequestType() {
		return CSQ_ReportUser.class;
	}

	public Class<?> getResponseType() {
		return CSA_ReportUser.class;
	}

	public JsonResponse handleRequest(JsonRequest request) throws Exception {
		// 判断sessionId
		CSQ_ReportUser params = (CSQ_ReportUser) request.getData();
		if (params.getFromUserId() == null || params.getReportUserId() == null || params.getReportType() == null) {
			// 参数错误
			return createErrorResponse(ServerErrors.PARAM_INVALID);
		}
		// 举报
		userSystem.reportUser(params.getFromUserId(), params.getReportUserId(), params.getReportType());

		CSA_ReportUser response = new CSA_ReportUser();
		return JsonResponse.create(response);
	}

}
